﻿namespace HuaWei
{
    using DevExpress.XtraEditors;
    using DevExpress.XtraGrid;
    using DevExpress.XtraGrid.Views.Base;
    using DevExpress.XtraGrid.Views.Grid;
    using DevExpress.XtraTreeList.Blending;
    using HuaWei.CommClass;
    using HuaWei.DAI;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class Form2 : Form
    {
        private Button button1;
        private DataColumn dataColumn;
        private DataColumn dataColumn1;
        private DataColumn dataColumn2;
        private DataColumn dataColumn3;
        private DataColumn dataColumn4;
        private DataColumn dataColumn5;
        private DataColumn dataColumn6;
        private DataTable dataTable;
        private DataTable dataTable1;
        private GridControl gridControl1;
        private GridControl gridControl2;
        private GridView gridView1;
        private GridView gridView2;
        private IContainer icontainer = null;
        private SimpleButton simpleButton1;
        private SimpleButton simpleButton2;
        private SimpleButton simpleButton3;
        private SimpleButton simpleButton4;
        private DataSet vroAaJyIa;
        private XtraTreeListBlending xtraTreeListBlending;

        public Form2()
        {
            this.InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataTable table = ReadWriterExcel.ImportExcel();
            this.gridControl1.DataSource = table;
            this.gridControl1.DefaultView.PopulateColumns();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.icontainer != null))
            {
                this.icontainer.Dispose();
            }
            base.Dispose(disposing);
        }

        private void gridView1_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
        {
            if (e.RowHandle == 1)
            {
                e.Appearance.ForeColor = Color.Red;
            }
            if (e.RowHandle == 3)
            {
                e.Appearance.ForeColor = Color.Red;
            }
        }

        private void gridView1_CustomRowFilter(object sender, RowFilterEventArgs e)
        {
        }

        private void gridView2_RowStyle(object sender, RowStyleEventArgs e)
        {
            e.Appearance.ForeColor = Color.Red;
        }

        private void InitializeComponent()
        {
            GridLevelNode node = new GridLevelNode();
            GridLevelNode node2 = new GridLevelNode();
            this.xtraTreeListBlending = new XtraTreeListBlending();
            this.vroAaJyIa = new DataSet();
            this.dataTable = new DataTable();
            this.dataColumn = new DataColumn();
            this.dataColumn1 = new DataColumn();
            this.dataColumn2 = new DataColumn();
            this.dataTable1 = new DataTable();
            this.dataColumn3 = new DataColumn();
            this.dataColumn4 = new DataColumn();
            this.dataColumn5 = new DataColumn();
            this.dataColumn6 = new DataColumn();
            this.simpleButton1 = new SimpleButton();
            this.simpleButton2 = new SimpleButton();
            this.gridControl1 = new GridControl();
            this.gridView1 = new GridView();
            this.button1 = new Button();
            this.simpleButton3 = new SimpleButton();
            this.simpleButton4 = new SimpleButton();
            this.gridControl2 = new GridControl();
            this.gridView2 = new GridView();
            this.vroAaJyIa.BeginInit();
            this.dataTable.BeginInit();
            this.dataTable1.BeginInit();
            this.gridControl1.BeginInit();
            this.gridView1.BeginInit();
            this.gridControl2.BeginInit();
            this.gridView2.BeginInit();
            base.SuspendLayout();
            this.vroAaJyIa.DataSetName = "NewDataSet";
            this.vroAaJyIa.Tables.AddRange(new DataTable[] { this.dataTable, this.dataTable1 });
            this.dataTable.Columns.AddRange(new DataColumn[] { this.dataColumn, this.dataColumn1, this.dataColumn2 });
            this.dataTable.TableName = "st_wzfl";
            this.dataColumn.ColumnName = "ID";
            this.dataColumn1.ColumnName = "PID";
            this.dataColumn2.ColumnName = "Name";
            this.dataTable1.Columns.AddRange(new DataColumn[] { this.dataColumn3, this.dataColumn4, this.dataColumn5, this.dataColumn6 });
            this.dataTable1.TableName = "st_wzxx";
            this.dataColumn3.ColumnName = "ID";
            this.dataColumn4.ColumnName = "MasterID";
            this.dataColumn5.ColumnName = "BH";
            this.dataColumn6.ColumnName = "MC";
            this.simpleButton1.Location = new Point(0x33, 12);
            this.simpleButton1.Name = "simpleButton1";
            this.simpleButton1.Size = new Size(0x4b, 0x17);
            this.simpleButton1.TabIndex = 1;
            this.simpleButton1.Text = "simpleButton1";
            this.simpleButton1.Click += new EventHandler(this.simpleButton1_Click);
            this.simpleButton2.Location = new Point(0x91, 12);
            this.simpleButton2.Name = "simpleButton2";
            this.simpleButton2.Size = new Size(0x4b, 0x17);
            this.simpleButton2.TabIndex = 2;
            this.simpleButton2.Text = "simpleButton2";
            this.simpleButton2.Click += new EventHandler(this.simpleButton2_Click);
            node.RelationName = "Level1";
            this.gridControl1.LevelTree.Nodes.AddRange(new GridLevelNode[] { node });
            this.gridControl1.Location = new Point(0x33, 0x47);
            this.gridControl1.MainView = this.gridView1;
            this.gridControl1.Name = "gridControl1";
            this.gridControl1.Size = new Size(0x162, 0x137);
            this.gridControl1.TabIndex = 5;
            this.gridControl1.ViewCollection.AddRange(new DevExpress.XtraGrid.Views.Base.BaseView[] { this.gridView1 });
            this.gridView1.GridControl = this.gridControl1;
            this.gridView1.HorzScrollVisibility = ScrollVisibility.Always;
            this.gridView1.Name = "gridView1";
            this.gridView1.OptionsView.ColumnAutoWidth = false;
            this.gridView1.CustomDrawCell += new RowCellCustomDrawEventHandler(this.gridView1_CustomDrawCell);
            this.gridView1.CustomRowFilter += new RowFilterEventHandler(this.gridView1_CustomRowFilter);
            this.button1.AllowDrop = true;
            this.button1.Location = new Point(0xe2, 12);
            this.button1.Name = "button1";
            this.button1.Size = new Size(0x4b, 0x17);
            this.button1.TabIndex = 7;
            this.button1.Text = "button1";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new EventHandler(this.button1_Click);
            this.simpleButton3.Location = new Point(0x134, 12);
            this.simpleButton3.Name = "simpleButton3";
            this.simpleButton3.Size = new Size(0x4b, 0x17);
            this.simpleButton3.TabIndex = 8;
            this.simpleButton3.Text = "simpleButton3";
            this.simpleButton3.Click += new EventHandler(this.simpleButton3_Click);
            this.simpleButton4.Location = new Point(390, 13);
            this.simpleButton4.Name = "simpleButton4";
            this.simpleButton4.Size = new Size(0x4b, 0x17);
            this.simpleButton4.TabIndex = 9;
            this.simpleButton4.Text = "simpleButton4";
            this.simpleButton4.Click += new EventHandler(this.simpleButton4_Click);
            node2.RelationName = "Level1";
            this.gridControl2.LevelTree.Nodes.AddRange(new GridLevelNode[] { node2 });
            this.gridControl2.Location = new Point(0x19b, 0x47);
            this.gridControl2.MainView = this.gridView2;
            this.gridControl2.Name = "gridControl2";
            this.gridControl2.Size = new Size(0x162, 0x137);
            this.gridControl2.TabIndex = 10;
            this.gridControl2.ViewCollection.AddRange(new DevExpress.XtraGrid.Views.Base.BaseView[] { this.gridView2 });
            this.gridView2.GridControl = this.gridControl2;
            this.gridView2.Name = "gridView2";
            this.gridView2.RowStyle += new RowStyleEventHandler(this.gridView2_RowStyle);
            this.AllowDrop = true;
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            base.ClientSize = new Size(0x322, 0x18a);
            base.Controls.Add(this.gridControl2);
            base.Controls.Add(this.simpleButton4);
            base.Controls.Add(this.simpleButton3);
            base.Controls.Add(this.button1);
            base.Controls.Add(this.gridControl1);
            base.Controls.Add(this.simpleButton2);
            base.Controls.Add(this.simpleButton1);
            base.Name = "Form2";
            this.Text = "Form2";
            base.Load += new EventHandler(this.lquywmUul);
            this.vroAaJyIa.EndInit();
            this.dataTable.EndInit();
            this.dataTable1.EndInit();
            this.gridControl1.EndInit();
            this.gridView1.EndInit();
            this.gridControl2.EndInit();
            this.gridView2.EndInit();
            base.ResumeLayout(false);
        }

        private void lquywmUul(object sender, EventArgs e)
        {
        }

        private void method()
        {
        }

        private void method1(object sender, EventArgs e)
        {
            this.method();
        }

        private void method2(object sender, EventArgs e)
        {
        }

        private void method3(object sender, EventArgs e)
        {
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            IDataAccess access = DBHelp.IniIDA();
            access.BeginTrans();
            access.Update(this.vroAaJyIa, "st_wzfl");
            access.Update(this.vroAaJyIa, "st_wzxx");
            access.Commit();
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {
            string str = "";
            for (int i = 0; i <= (this.gridView1.Columns.Count - 1); i++)
            {
                str = str + this.gridView1.VisibleColumns[i].FieldName;
            }
            string str2 = this.gridView1.FocusedColumn.FieldName.ToString().Trim();
            str = str + "    开始字段名： " + str2;
            int rowPos = DHelp.GetRowPos(this.gridControl1);
            str = str + "    开始列：" + Convert.ToString(rowPos);
            DataTable dataSource = this.gridControl1.DataSource as DataTable;
            foreach (DataRow row in dataSource.Rows)
            {
                string str3 = row[str2].ToString().Replace(" ", "").Replace("－", "-");
                row[str2] = str3;
            }
            this.gridControl1.DataSource = dataSource;
            this.Text = str;
        }

        private void simpleButton4_Click(object sender, EventArgs e)
        {
            int rowPos = DHelp.GetRowPos(this.gridControl1);
            int visibleIndex = this.gridView1.FocusedColumn.VisibleIndex;
            string[] fieldName = new string[this.gridView1.Columns.Count - visibleIndex];
            for (int i = 0; i < fieldName.Length; i++)
            {
                fieldName[i] = this.gridView1.VisibleColumns[visibleIndex + i].FieldName;
            }
            OpenFileDialog dialog = new OpenFileDialog();
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    DataTable table = ReadWriterExcel.GetData(dialog.FileName, fieldName, rowPos);
                    this.gridControl2.DataSource = table;
                    this.gridControl2.DefaultView.PopulateColumns();
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
        }
    }
}

